package com.small.nine.wxmp.common.lock;

import com.small.nine.wxmp.common.constant.RedisConstant;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Redisson lock 工具类
 *
 * @author sheng_zs@126.com
 * @date 2021-08-03 15:27
 */
@Lazy
@Component
public class RedisLock {
    @Resource
    private RedissonClient redissonClient;

    /**
     * 返回 RLock 可重入锁
     *
     * @param key redis key
     * @return {@link org.redisson.api.RLock}
     */
    public RLock getRLock(String key) {
        return redissonClient.getLock(RedisConstant.REDISSON_LOCK_KEY + key);
    }
}
